package cn.jee.dao;

import cn.jee.domain.Stu;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;
@Mapper
public interface StuMapper {
  //利用注释定义要执行的sql语句
  @Cacheable("stu")
  @Select("select * from stu")
  List<Stu> find();

  @Select("select * from stu where id=#{id}")
  Stu findById(long id);

  @CacheEvict(value="stu",allEntries = true)
  @Insert("insert into stu(username) values(#{username})")
  //stu.getId()可以得到自动产生的值，同时keyProperty指定哪一个变量接受这个值
  //keyColumn哪一列自动产生值
  @Options(useGeneratedKeys = true,keyProperty = "id")
  int add(Stu stu);
}
